// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.
//
// ███╗   ██╗ ██████╗ ████████╗██╗ ██████╗███████╗
// ████╗  ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝
// ██╔██╗ ██║██║   ██║   ██║   ██║██║     █████╗
// ██║╚██╗██║██║   ██║   ██║   ██║██║     ██╔══╝
// ██║ ╚████║╚██████╔╝   ██║   ██║╚██████╗███████╗
// ╚═╝  ╚═══╝ ╚═════╝    ╚═╝   ╚═╝ ╚═════╝╚══════╝
// ------------------------------------------------
//
// This file is automatically generated.
// Please do not edit these files manually.
//
// ------------------------------------------------

#nullable restore

using Elastic.Clients.Elasticsearch.Serverless.Fluent;
using Elastic.Clients.Elasticsearch.Serverless.Serialization;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace Elastic.Clients.Elasticsearch.Serverless.MachineLearning;

public sealed partial class DataframeEvaluationRegressionMetrics
{
	/// <summary>
	/// <para>Pseudo Huber loss function.</para>
	/// </summary>
	[JsonInclude, JsonPropertyName("huber")]
	public Elastic.Clients.Elasticsearch.Serverless.MachineLearning.DataframeEvaluationRegressionMetricsHuber? Huber { get; set; }

	/// <summary>
	/// <para>Average squared difference between the predicted values and the actual (ground truth) value. For more information, read this wiki article.</para>
	/// </summary>
	[JsonInclude, JsonPropertyName("mse")]
	public IDictionary<string, object>? Mse { get; set; }

	/// <summary>
	/// <para>Average squared difference between the logarithm of the predicted values and the logarithm of the actual (ground truth) value.</para>
	/// </summary>
	[JsonInclude, JsonPropertyName("msle")]
	public Elastic.Clients.Elasticsearch.Serverless.MachineLearning.DataframeEvaluationRegressionMetricsMsle? Msle { get; set; }

	/// <summary>
	/// <para>Proportion of the variance in the dependent variable that is predictable from the independent variables.</para>
	/// </summary>
	[JsonInclude, JsonPropertyName("r_squared")]
	public IDictionary<string, object>? RSquared { get; set; }
}

public sealed partial class DataframeEvaluationRegressionMetricsDescriptor : SerializableDescriptor<DataframeEvaluationRegressionMetricsDescriptor>
{
	internal DataframeEvaluationRegressionMetricsDescriptor(Action<DataframeEvaluationRegressionMetricsDescriptor> configure) => configure.Invoke(this);

	public DataframeEvaluationRegressionMetricsDescriptor() : base()
	{
	}

	private Elastic.Clients.Elasticsearch.Serverless.MachineLearning.DataframeEvaluationRegressionMetricsHuber? HuberValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.MachineLearning.DataframeEvaluationRegressionMetricsHuberDescriptor HuberDescriptor { get; set; }
	private Action<Elastic.Clients.Elasticsearch.Serverless.MachineLearning.DataframeEvaluationRegressionMetricsHuberDescriptor> HuberDescriptorAction { get; set; }
	private IDictionary<string, object>? MseValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.MachineLearning.DataframeEvaluationRegressionMetricsMsle? MsleValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.MachineLearning.DataframeEvaluationRegressionMetricsMsleDescriptor MsleDescriptor { get; set; }
	private Action<Elastic.Clients.Elasticsearch.Serverless.MachineLearning.DataframeEvaluationRegressionMetricsMsleDescriptor> MsleDescriptorAction { get; set; }
	private IDictionary<string, object>? RSquaredValue { get; set; }

	/// <summary>
	/// <para>Pseudo Huber loss function.</para>
	/// </summary>
	public DataframeEvaluationRegressionMetricsDescriptor Huber(Elastic.Clients.Elasticsearch.Serverless.MachineLearning.DataframeEvaluationRegressionMetricsHuber? huber)
	{
		HuberDescriptor = null;
		HuberDescriptorAction = null;
		HuberValue = huber;
		return Self;
	}

	public DataframeEvaluationRegressionMetricsDescriptor Huber(Elastic.Clients.Elasticsearch.Serverless.MachineLearning.DataframeEvaluationRegressionMetricsHuberDescriptor descriptor)
	{
		HuberValue = null;
		HuberDescriptorAction = null;
		HuberDescriptor = descriptor;
		return Self;
	}

	public DataframeEvaluationRegressionMetricsDescriptor Huber(Action<Elastic.Clients.Elasticsearch.Serverless.MachineLearning.DataframeEvaluationRegressionMetricsHuberDescriptor> configure)
	{
		HuberValue = null;
		HuberDescriptor = null;
		HuberDescriptorAction = configure;
		return Self;
	}

	/// <summary>
	/// <para>Average squared difference between the predicted values and the actual (ground truth) value. For more information, read this wiki article.</para>
	/// </summary>
	public DataframeEvaluationRegressionMetricsDescriptor Mse(Func<FluentDictionary<string, object>, FluentDictionary<string, object>> selector)
	{
		MseValue = selector?.Invoke(new FluentDictionary<string, object>());
		return Self;
	}

	/// <summary>
	/// <para>Average squared difference between the logarithm of the predicted values and the logarithm of the actual (ground truth) value.</para>
	/// </summary>
	public DataframeEvaluationRegressionMetricsDescriptor Msle(Elastic.Clients.Elasticsearch.Serverless.MachineLearning.DataframeEvaluationRegressionMetricsMsle? msle)
	{
		MsleDescriptor = null;
		MsleDescriptorAction = null;
		MsleValue = msle;
		return Self;
	}

	public DataframeEvaluationRegressionMetricsDescriptor Msle(Elastic.Clients.Elasticsearch.Serverless.MachineLearning.DataframeEvaluationRegressionMetricsMsleDescriptor descriptor)
	{
		MsleValue = null;
		MsleDescriptorAction = null;
		MsleDescriptor = descriptor;
		return Self;
	}

	public DataframeEvaluationRegressionMetricsDescriptor Msle(Action<Elastic.Clients.Elasticsearch.Serverless.MachineLearning.DataframeEvaluationRegressionMetricsMsleDescriptor> configure)
	{
		MsleValue = null;
		MsleDescriptor = null;
		MsleDescriptorAction = configure;
		return Self;
	}

	/// <summary>
	/// <para>Proportion of the variance in the dependent variable that is predictable from the independent variables.</para>
	/// </summary>
	public DataframeEvaluationRegressionMetricsDescriptor RSquared(Func<FluentDictionary<string, object>, FluentDictionary<string, object>> selector)
	{
		RSquaredValue = selector?.Invoke(new FluentDictionary<string, object>());
		return Self;
	}

	protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
	{
		writer.WriteStartObject();
		if (HuberDescriptor is not null)
		{
			writer.WritePropertyName("huber");
			JsonSerializer.Serialize(writer, HuberDescriptor, options);
		}
		else if (HuberDescriptorAction is not null)
		{
			writer.WritePropertyName("huber");
			JsonSerializer.Serialize(writer, new Elastic.Clients.Elasticsearch.Serverless.MachineLearning.DataframeEvaluationRegressionMetricsHuberDescriptor(HuberDescriptorAction), options);
		}
		else if (HuberValue is not null)
		{
			writer.WritePropertyName("huber");
			JsonSerializer.Serialize(writer, HuberValue, options);
		}

		if (MseValue is not null)
		{
			writer.WritePropertyName("mse");
			JsonSerializer.Serialize(writer, MseValue, options);
		}

		if (MsleDescriptor is not null)
		{
			writer.WritePropertyName("msle");
			JsonSerializer.Serialize(writer, MsleDescriptor, options);
		}
		else if (MsleDescriptorAction is not null)
		{
			writer.WritePropertyName("msle");
			JsonSerializer.Serialize(writer, new Elastic.Clients.Elasticsearch.Serverless.MachineLearning.DataframeEvaluationRegressionMetricsMsleDescriptor(MsleDescriptorAction), options);
		}
		else if (MsleValue is not null)
		{
			writer.WritePropertyName("msle");
			JsonSerializer.Serialize(writer, MsleValue, options);
		}

		if (RSquaredValue is not null)
		{
			writer.WritePropertyName("r_squared");
			JsonSerializer.Serialize(writer, RSquaredValue, options);
		}

		writer.WriteEndObject();
	}
}